package com.cooper.beautyseesee;

import com.cooper.beautyseesee.data.BeautyType;
import com.cooper.scraper.ScrapersDownTask;
import com.cooper.scraper.ScrapersDownTask.ScrapersDownListener;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class BeautyListFragment extends Fragment implements ScrapersDownListener{
	
	public static BeautyListFragment newInstance(BeautyType beautyType){
		BeautyListFragment result = new BeautyListFragment();
		Bundle bundle = new Bundle();
		bundle.putParcelable("BEAUTY_TYPE", beautyType);
		result.setArguments(bundle);
		return result;
	}
		
	public BeautyListFragment(){
		super();
		setRetainInstance(true);
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		return inflater.inflate(R.layout.beauty_list, container,false);
	}
	
	private BeautyType beautyType;
	
	private void listBeauty(){
		if (!isRemoving()){
			((MainActivity)getActivity()).contentFinish();
			beautyType = getArguments().getParcelable("BEAUTY_TYPE");
		}
	}
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		((MainActivity)getActivity()).contentWaiting();
		if (ScrapersDownTask.isReady()){
			listBeauty();	
		}else{
			ScrapersDownTask.collectionScraper(getActivity(),MainActivity.INFO_URL, this, false);
		}
	}

	@Override
	public void onScrapersDownComplete() {
		listBeauty();		
	}
	
	//public BeautyListFragment(int beautyTpye){
	//	super();
	//	this.beautyType = beautyTpye;
	//	this.setRetainInstance(true);
	//}

}
